package com.nmf.pc.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.nmf.dao.gen.BaseCitiesMapper;
import com.nmf.dao.gen.BaseProvincesMapper;
import com.nmf.dao.gen.bean.BaseCities;
import com.nmf.dao.gen.bean.BaseCitiesExample;
import com.nmf.dao.gen.bean.BaseProvinces;
import com.nmf.dao.gen.bean.BaseProvincesExample;
import com.nmf.pc.vo.ReturnResult;

@Controller
@RequestMapping(value = "/pc")
public class PcBaseDataController {
	@Autowired
	BaseProvincesMapper baseProvincesMapper;
	@Autowired
	BaseCitiesMapper baseCitiesMapper;
	@RequestMapping(value = { "p/light/provinces" }, method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public ReturnResult provinces(HttpServletRequest request, HttpServletResponse response) throws IOException {
		ReturnResult returnResult = new ReturnResult();
		List<BaseProvinces>  plist = baseProvincesMapper.selectByExample(new BaseProvincesExample());
		returnResult.setData(plist);
		return returnResult;
	}
	
	@RequestMapping(value = { "p/light/cities" }, method = { RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public ReturnResult cities(String provinceId,HttpServletRequest request, HttpServletResponse response) throws IOException {
		ReturnResult returnResult = new ReturnResult();
		BaseCitiesExample baseCitiesExample = new BaseCitiesExample();
		
		BaseCitiesExample.Criteria criteria = baseCitiesExample.createCriteria();
		criteria.andProvinceIdEqualTo(provinceId);
		
		List<BaseCities>  plist = baseCitiesMapper.selectByExample(baseCitiesExample);
		
		returnResult.setData(plist);
		return returnResult;
	}
}
